package com.shelpe.services.lexicon.service;

import java.util.ArrayList;
import java.util.List;

import com.shelpe.services.lexicon.entity.KeywordRecommend;

import lombok.Data;

@Data
public class WordChunk {

	private WordChunk next;
	private int limit = 100;
	private int maxLenth = 500;
	
	private List<String> words;
	
	private int totalLength = 0;
	
	public WordChunk(int limit){
		this.limit = limit;
	}
	public WordChunk addWord(String word){
		if(words == null){
			this.words = new ArrayList<String>();
		}
		if(this.words.size() < limit && this.totalLength < this.maxLenth){
			this.words.add(word);
			totalLength = totalLength + word.length();
		}else{
			if(next == null){
				WordChunk newChunk = new WordChunk(this.limit);
				next = newChunk;
			}
			next.addWord(word);
		}
		return this;
	}
	
	public static interface ChunkCallback{
		void call(WordChunk chunk, List<KeywordRecommend> recommends, ChunkCallback next);
	}
}
